Add Roles to a Data Source Server
{ addRolesToServer }
Add roles to a Data Source server.
Method
/API2/dataSources/addRolesToServer
API Section: /API2/dataSources
API Version: 2.0
From Release: 2018.5
Method operates via POST actions only.
Input Parameters
Object with roles and items to be added.
Output Response
Description of Response Type
Generic API response object with success or failure flag and related messages.
Examples
Data Source Operations (JavaScript):
This example demonstrates how to operate with data sources.
The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.
var pyramidURL = "http://mysite.com/api2/";
let token = callApi("auth/authenticateUser",{
"data":{
"userName":"adminUser",
"password":"12345678"
}
},false);
log("got token "+token);
let findRole = callApi("access/getRolesByName",{
"data": {
"searchValue": "role1",
"searchMatchType": 2
},
"auth": token
});
let roleId=findRole.data[0].roleId;
log("found role with id= "+ roleId);
let createDataServer = callApi("dataSources/createDataServer",{
"serverData": {
"serverName": "new server",
"serverType":13,
"serverIp": "172.29.3.178",
"port":5060,
"serverAuthenticationMethod":0,
"userName":"default",
"password":"password",
},
"auth": token
});
let dataServerId=createDataServer.data.modifiedList[0].id;
log("created dataserver= "+ dataServerId);
let addRolesToServer = callApi("dataSources/addRolesToServer",{
"itemRoles": {
"itemId":dataServerId,
"itemRolePairList":[{
"roleId":roleId,
"accessType":2
}]
},
"auth": token
});
log("added role1 to the newly created server");
let getRolesByServer= callApi("dataSources/getRolesByServer",{
"serverId": dataServerId,
"auth": token
});
let recognizeDataBase = callApi("dataSources/recognizeDataBase",{
"dataBaseRecognitionObject": {
"serverId":dataServerId,
"dbName":"PyramidDemo"
},
"auth": token
});
let databaseId=recognizeDataBase.data.modifiedList[0].id;
log("found database "+databaseId+" at the dataserver");
let addRolesToDataBase = callApi("dataSources/addRolesToDataBase",{
"itemRoles": {
"itemId":databaseId,
"itemRolePairList":[{
"roleId":roleId,
"accessType":3
}]
},
"auth": token
});
let file="http://myOtherSite.com/SampleModel.pie";
let modelData=readPieFile(file);
let importModel = callApi("dataSources/importModel",{
"modelApiObject": {
"fileZippedData":modelData,
"databaseId":databaseId,
"materializedRoleAssignmentType":3
},
"auth": token
}).data;
let addRolesToModel = callApi("dataSources/addRolesToModel",{
"itemRoles": {
"itemId":importModel.modelId,
"itemRolePairList":[{
"roleId":roleId,
"accessType":3
}]
},
"auth": token
});
let deleteMaterializedModel = callApi("dataSources/deleteMaterializedModel",{
"modelId": importModel.modelId,
"auth": token
});
let deleteDataBase=callApi("dataSources/deleteDataBase",{
"databaseId": databaseId,
"auth": token
});
let deleteDataSource = callApi("dataSources/deleteDataSource",{
"sourceId": dataServerId,
"auth": token
});
function log(msg){
document.write(msg);
console.log(msg);
}
function callApi(path,data,parseResult=true){
var xhttp = new XMLHttpRequest();
xhttp.open("POST", pyramidURL+path, false);
xhttp.send(JSON.stringify(data));
if(parseResult){
return JSON.parse(xhttp.responseText);
}else{
return xhttp.responseText;
}
}
function readPieFile(file){
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.send(null);
rawFile.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
return request.responseText;
}
}
}